import Confirm from './confirm';
import {processOptions} from '../../utils/index';
let $vm;
export default {
  install(Vue,  options = {}) {
    if (!$vm) {
        const ConfirmComponent= Vue.extend(Confirm);

        $vm = new ConfirmComponent({
            el: document.createElement('div')
        });
        document.body.appendChild($vm.$el);
    }
    const confirmComponent = {
        show(options) {
            if(typeof options =='object'){
              processOptions($vm,options)
            }
            $vm.isShowConfirm = true;
            $vm.$off('onCancel')
            $vm.$off('onConfirm')
            $vm.$on('onCancel', () => {
              options && options.onCancel && options.onCancel()
            })
            $vm.$on('onConfirm', msg => {
              options && options.onConfirm && options.onConfirm(msg)
            })
        },
        hide() {
            $vm.isShowConfirm = false;
        }
    }
    if(!Vue.$ifast){
      Vue.$ifast={}
    }
    if (!Vue.$ifast.confirm) {
        Vue.$ifast = {
          confirm:confirmComponent
        };
    }
    Vue.mixin({
        created() {
          if(!this.$ifast){
            this.$ifast={
              confirm:confirmComponent
            }
          }else{
            this.$ifast.confirm=confirmComponent;
          }
          // this.$ifast.confirm =confirmComponent;
        }
    })
  }
}